package com.school.util;

import com.alibaba.fastjson.JSON;
import com.school.vo.R;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 响应数据到前端
 */
public class ResponseJsonUtil {
    public static void write(HttpServletResponse resp, R r){
        try {
            resp.setCharacterEncoding("utf8");
            // 返回JSON格式
            resp.setContentType("application/json");
            PrintWriter writer = resp.getWriter();
            // String json = "{\"code\":\"0\",\"message\":\"成功\",\"data\":{\"name\":\"张三\",\"pswd\":\"123456\"}}";
            // fastJSON
            // 修改...
            writer.write(JSON.toJSONString(r));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
